package com.neusoft.crm.controller;

import com.alibaba.druid.proxy.jdbc.DataSourceProxyImpl;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
import com.neusoft.crm.mapper.SalePlanMapper;
import com.neusoft.crm.po.SaleChance;
import com.neusoft.crm.po.SalePlan;
import com.neusoft.crm.service.ISaleChanceService;
import com.neusoft.crm.service.SalePlanService;
import lombok.extern.log4j.Log4j2;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.io.Serializable;
import java.util.List;

@RestController
@Log4j2
public class SalePlanController {

    @Resource
    private SalePlanService salePlanService;

    @Resource
    private SalePlanMapper salePlanMapper;

    @Resource
    private ISaleChanceService saleChanceService;



    @RequestMapping("/selectSalePlan")
    public List<SalePlan> selectSalePlan(@RequestBody SaleChance saleChance) {
        LambdaQueryWrapper<SalePlan> wrapper = new LambdaQueryWrapper<>();
        wrapper.eq(SalePlan::getPlanChcId, saleChance.getChanceId());
        return salePlanMapper.selectList(wrapper);
    }

    @RequestMapping("/saleChancePlanDelete")
    public int saleChancePlanDelete(@RequestBody SaleChance saleChance){
        return salePlanMapper.deleteById((Serializable) saleChance);
    }


    @RequestMapping("/addSaleChancePlan")
    public int addSaleChancePlan(@RequestBody SalePlan salePlan){
        int planChcid =salePlan.getPlanChcId();
        UpdateWrapper updateWrapper = new UpdateWrapper();
        updateWrapper.eq("chance_id",planChcid);
        updateWrapper.set("chance_Status",1);
        saleChanceService.update(null, updateWrapper);
        return salePlanMapper.insert(salePlan);
    }

    @RequestMapping("/updateSaleChancePlan")
    public int updateSaleChancePlan(@RequestBody SalePlan salePlan) {
        return salePlanMapper.updateById(salePlan);
    }





}
